package task;

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method 'GET'
        url value(consumer(regex('api/v2/tasks/[0-9]+')), producer('api/v2/tasks/1'))
    }
    response {
        status 200
        body("""
            {
                "id":1,
                "programId": 1,
                "paperId": 1,
                "topicId": 1,
                "orderNumber":1,
                "content":"content",
                "createTime":"2018-01-01 00:00:00.0",
                "topic":{
                    "id": 1,
                    "programId": 1,
                    "title": "title",
                    "createTime": "2018-01-01 00:00:00.0",
                    "orderNumber": 1
                }
            }
        """)
        headers {
            contentType(applicationJsonUtf8())
        }
        bodyMatchers {
            jsonPath('$.[*]',byType())
            jsonPath('$.id', byRegex(number()))
            jsonPath('$.programId', byRegex(number()))
            jsonPath('$.paperId', byRegex(number()))
            jsonPath('$.topicId', byRegex(number()))
            jsonPath('$.orderNumber', byRegex(number()))
            jsonPath('$.createTime', byRegex(nonEmpty()))
            jsonPath('$.content', byRegex(nonEmpty()))
            jsonPath('$.topic.id', byRegex(number()))
            jsonPath('$.topic.programId', byRegex(number()))
            jsonPath('$.topic.title', byRegex(nonEmpty()))
            jsonPath('$.topic.createTime', byRegex(nonEmpty()))
            jsonPath('$.topic.orderNumber', byRegex(number()))
        }
    }
}